package com.ruoyi.interview.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.interview.domain.InterviewInfo;
import com.ruoyi.interview.service.AddExcelService3;
import com.ruoyi.student.domain.StudentInfo;
import com.ruoyi.student.service.AddExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @projectName: employmentSystem
 * @package: com.ruoyi.student.controller
 * @className: AddExcelController
 * @author: ximu
 * @description: TODO
 * @date: 2022/5/2 16:47
 * @version: 1.0
 */
@RestController
@RequestMapping("/interview/excel")
public class AddExcelController3 {

    @Autowired
    private AddExcelService3 addExcelService3;

    @Autowired
    private TokenService tokenService;

    /**
     * 导入数据管理列表
     */
    @Log(title = "数据管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<InterviewInfo> util = new ExcelUtil<InterviewInfo>(InterviewInfo.class);
        List<InterviewInfo> interviewInfoList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = addExcelService3.importData(interviewInfoList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<InterviewInfo> util = new ExcelUtil<InterviewInfo>(InterviewInfo.class);
        return util.importTemplateExcel("面试信息模板");
    }


}
